<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>分配编标</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="1">
                    <div class="opt-btn-group">
                        <div><span>分配信息</span></div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th style="width: 230px">项目名称</th>
                            <th style="width: 230px">投标单位</th>
                            <th>土建预算</th>
                            <th>提成占比(%)</th>
                            <th>安装预算</th>
                            <th>提成占比(%)</th>
                            <th>资审</th>
                            <th>提成占比(%)</th>
                            <th>预算审核</th>
                            <th>资料审核</th>
                            <th>备注</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="list_list" style="min-height: 400px;"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>

    </div>
</form>
<script>
    var param_ids = getQueryVariable('ids') || '';
    //待处理

    function choose_userid(obj, dom){
        var index = $(obj).parents('tr').find('td:first-child').text();
        index = parseInt(index) - 1;
        openPage('../public/choose_userpart.php?dom='+dom+'&index='+index+'&page=bidtou','770px','490px');
    }


    function set_list_user_tags(data) {
        var str = '';
        for (var key in data){
            data[key].part = data[key].part || '';
            str += '<div class="tags">';
            str += '<div ' +
                'title="'+data[key].name+'" '+
                'data-id="'+data[key].id+'" '+
                'data-part="'+data[key].part+'" '+
                '>';
            str += data[key].name+'</div>';
            str += '<i class="layui-icon" onclick="closeTanTag(this)">&#x1006;</i></div>';
        }
        return str;
    }


    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_bid_fen,data:{ids:param_ids}}).done(function(res){
            if (res.code === 2000) {
                var touinfo = res.data.touinfo;


                short_table_opt_func('', 1);


                var list = res.data.touinfo;
                if(list.length > 0){
                    for (var key in list){
                        var str = '';
                        var nums = parseInt(key)+1;
                        str += '<tr>';
                        str += '<td style="width: 45px">'+nums+'</td>';
                        str += '<td style="width: 250px"><input type="text" class="layui-input bidname disabled" disabled value="'+list[key].bidname+'"></td>';
                        str += '<td style="width: 250px"><input type="text" class="layui-input touunit disabled" disabled id="'+list[key].id+'" value="'+list[key].touunit+'"></td>';

                        str += '<td><div class="tanxian" style="border: 0;">';
                        str += '<div class="tanxianclick" onclick="choose_userid(this,\'suan_tu\')"></div>';
                        str += '<div class="tanxiannei suan_tu">'+set_list_user_tags(list[key].suan_tu_info)+'</div></div></td>';

                        str += '<td><input type="number" class="layui-input bi_tu" value="'+list[key].bi_tu+'"></td>';

                        str += '<td><div class="tanxian" style="border: 0;">';
                        str += '<div class="tanxianclick" onclick="choose_userid(this,\'suan_an\')"></div>';
                        str += '<div class="tanxiannei suan_an">'+set_list_user_tags(list[key].suan_an_info)+'</div></div></td>';


                        str += '<td><input type="number" class="layui-input bi_an" value="'+list[key].bi_an+'"></td>';

                        str += '<td><div class="tanxian" style="border: 0;">';
                        str += '<div class="tanxianclick" onclick="choose_userid(this,\'zi_shen\')"></div>';
                        str += '<div class="tanxiannei zi_shen">'+set_list_user_tags(list[key].zi_shen_info)+'</div></div></td>';

                        str += '<td><input type="number" class="layui-input bi_shen" value="'+list[key].bi_shen+'"></td>';

                        str += '<td><div class="tanxian" style="border: 0;">';
                        str += '<div class="tanxianclick" onclick="choose_userid(this,\'shen_suan\')"></div>';
                        str += '<div class="tanxiannei shen_suan">'+set_list_user_tags(list[key].shen_suan_info)+'</div></div></td>';
                        str += '<td><div class="tanxian" style="border: 0;">';
                        str += '<div class="tanxianclick" onclick="choose_userid(this,\'shen_zi\')"></div>';
                        str += '<div class="tanxiannei shen_zi">'+set_list_user_tags(list[key].shen_zi_info)+'</div></div></td>';

                        str += '<td><input type="text" class="layui-input explain" value="'+list[key].explain+'"></td>';
                        str += '</tr>';
                        $("#list_list").append(str);
                    }
                }
                update_refresh_row_func();




                initParseMoney();
                render_from();
            }
        });

        form.on('submit(add)', function(data){

            var validRes = $("#commentForm").valid();
            if(!validRes){return false;}


            var list = [''];
            try {
                $('#list_list tr').each(function (i) {
                    var id = $(this).find('.touunit').attr('id') || 0;
                    var suan_tu = $(this).find('.suan_tu>div>div').attr('data-id') || '';
                    var suan_an = $(this).find('.suan_an>div>div').attr('data-id') || '';
                    var zi_shen = $(this).find('.zi_shen>div>div').attr('data-id') || '';
                    var shen_suan = $(this).find('.shen_suan>div>div').attr('data-id') || '';
                    var shen_zi = $(this).find('.shen_zi>div>div').attr('data-id') || '';
                    var bi_tu = $(this).find('.bi_tu').val();
                    var bi_an = $(this).find('.bi_an').val();
                    var bi_shen = $(this).find('.bi_shen').val();
                    var explain = $(this).find('.explain').val();

                    list.push({
                        id:id,
                        suan_tu:suan_tu,
                        suan_an:suan_an,
                        zi_shen:zi_shen,
                        shen_suan:shen_suan,
                        shen_zi:shen_zi,
                        bi_tu:bi_tu,
                        bi_an:bi_an,
                        bi_shen:bi_shen,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".listerror").find('span').text(e.message);
                $(".listerror").show();
                return false;
            }
            $(".listerror").hide();
            data.field.list = list;






            data = parseMoney(data);
            data.field.ids = param_ids;
            facade.ajax({url: ask_bid_fen, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });




</script>
</body>
</html>
